/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Users {
    public static boolean insertUser(Entity.User user){
        try {
            String sql = "insert into tblUser values(?,?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, user.get_UserID());
            ps.setString(2, user.get_FullName());
            ps.setBoolean(3, user.is_Gender());
            ps.setString(4, user.get_Address());
            ps.setString(5, user.get_Birthday());
            ps.setString(6, user.get_Email());
            ps.setString(7, user.get_IdentityCard());
            ps.setString(8, user.get_Username());
            ps.setString(9, user.get_Password());
            ps.setString(10, user.get_RoleID());
            ps.setBoolean(11, user.is_Status());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static boolean updateUser(Entity.User user){
        try {

            String sql = "update tblUser set FullName=?, Gender=?, Address=?, Birthday=?, Email=?, IdentityCard=?, Username=?, Password=?, RoleID=?, Status=? where UserID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, user.get_FullName());
            ps.setBoolean(2, user.is_Gender());
            ps.setString(3, user.get_Address());
            ps.setString(4, user.get_Birthday());
            ps.setString(5, user.get_Email());
            ps.setString(6, user.get_IdentityCard());
            ps.setString(7, user.get_Username());
            ps.setString(8, user.get_Password());
            ps.setString(9, user.get_RoleID());
            ps.setBoolean(10, user.is_Status());
            ps.setString(11, user.get_UserID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static void deleteUser(String strUserID){
        try {

            String sql = "delete from tblUser where UserID = '" + strUserID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
